package com.zhiyou100.crowd.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou100.IService.ICommentService;
import com.zhiyou100.pojo.TbComments;
@Controller
@RequestMapping("comments")
public class CommentsController {
//导入service
	
@Resource
private ICommentService commentService;



//评论查询
@RequestMapping("queryAll.do")
public String query(@RequestParam(required=true,defaultValue="1")Integer page ,HttpServletRequest request) {
	//调用查询方法
	PageHelper.startPage(page,5);
	List<TbComments> tbComments = commentService.queryAll();
	
	//将数据放入域中
	PageInfo<TbComments> pageInfo = new PageInfo<TbComments>(tbComments);
	request.setAttribute("page", pageInfo);
	request.setAttribute("tbComments", tbComments);
	System.out.println(tbComments);
	return "user_comments";
}

//删除
@RequestMapping("delete.do")
public String deleteComment(Integer cmUsId) {
	boolean flag = commentService.deleteComment(cmUsId);
	if(flag) {
			return "forward:queryAll.do";
		}else {
			return "forward:queryAll.do";
		}
	}
}